package cn.flying.cloud.oauth.server.mvc;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import cn.flying.cloud.base.core.interceptor.RequestContextInterceptor;

/**
 * web mvc配置
 *
 * @author: admin
 * @date: 2023年04月19日 00:11
 * @version: 1.0
 */
@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 添加第一个静态资源路径映射（支持网关访问）
        registry.addResourceHandler("/api/oauth/static/**")
                .addResourceLocations("classpath:/static/");

        // 添加第二个静态资源路径映射（本地访问）
        registry.addResourceHandler("/oauth/static/**")
                .addResourceLocations("classpath:/static/");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册自己的拦截器,并设置拦截的请求路径
        //addPathPatterns为拦截此请求路径的请求
        //excludePathPatterns为不拦截此路径的请求
        String[] exPath = {"/**"};

        registry.addInterceptor(new RequestContextInterceptor()).addPathPatterns(new String[]{"/**"});
    }
}
